% 	Name		:: 	sthlm Beamer Theme  HEAVILY based on the hsrmbeamer theme (Benjamin Weiss)
%	Author		:: 	Mark Hendry Olson (mark@hendryolson.com)
%	Created		::	2013-07-31
%	Updated		::	June 23, 2015 at 23:58
%	Version		:: 	1.0.0
%	Email		:: 	mark@hendryolson.com
%	Website		:: 	http://hendryolson.com
%
% 	License		:: 	This file may be distributed and/or modified under the
%                  	GNU Public License.
%
%	Description	::	This presentation is a demonstration of the sthlm beamer
%					theme, which is HEAVILY based on the HSRM beamer theme created by Benjamin Weiss
%					(benjamin.weiss@student.hs-rm.de), which can be found on GitHub
%					<https://github.com/hsrmbeamertheme/hsrmbeamertheme>.
%
%	Contents	::	01. PACKAGE OPTIONS & SETUP
%					02. PACKAGES & TIKZ
%					03. COLOR AND FONT THEMES (BEAMER)
%					04. TITLE PAGE
%					05. TABLE OF CONTENTS
%					06. PROGRESS BAR & HEADLINE
%					07. SECTION PAGES
%					08. ITEMIZE
%					09. FOOTLINE
%					10. CAPTIONS
%					11. FRAME TITLE
%					12. IMAGES
%					13. BLOCKS

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	01. PACKAGE OPTIONS & SETUP
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\ProvidesPackage{beamerthemesthlm}

\newif\if@useTitleProgressBar
\@useTitleProgressBartrue
\DeclareOptionBeamer{noprogressbar}{\@useTitleProgressBarfalse}

\newif\if@protectFrameTitle
\@protectFrameTitlefalse
\DeclareOptionBeamer{protectframetitle}{\@protectFrameTitletrue}

\newif\if@dosthlmFooter
\@dosthlmFooterfalse
\DeclareOptionBeamer{sthlmFooter}{\@dosthlmFootertrue}

\newif\if@donewPxFont
\@donewPxFontfalse
\DeclareOptionBeamer{newPxFont}{\@donewPxFonttrue}

\newif\if@dosthlmStadFont
\@dosthlmStadFontfalse
\DeclareOptionBeamer{sthlmStadFont}{\@dosthlmStadFonttrue}

\newif\if@dovaligncolumns
\@dovaligncolumnsfalse
\DeclareOptionBeamer{dovaligncolumns}{\@dovaligncolumnstrue}

\newif\if@doSectionPage
\@doSectionPagetrue
\DeclareOptionBeamer{nosectionpage}{\@doSectionPagefalse}

\DeclareOptionBeamer{nooffset}{\setlength{\@sthlm@voffset}{0em}}

\DeclareOptionBeamer*{%
  \PackageWarning{beamerthemesthlm}{Unknown option `\CurrentOption'}%
}

\newlength{\@sthlm@voffset}
\setlength{\@sthlm@voffset}{2em}

\ProcessOptionsBeamer
\mode<presentation>

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	02. PACKAGES & TIKZ
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\RequirePackage{amsmath}
\RequirePackage{tikz}
\RequirePackage{verbatim}
\RequirePackage{etoolbox}
\RequirePackage{booktabs}
\RequirePackage{ragged2e}
\RequirePackage[yyyymmdd]{datetime}
\RequirePackage{tabularx}
\RequirePackage{wasysym}
\RequirePackage{pgfplots}
\RequirePackage{listings}

\usetikzlibrary{backgrounds}
\usetikzlibrary{calc}

\lstnewenvironment{sthlmLatex}
{\lstset{
language=[LaTeX]TeX,
basicstyle=\small\ttfamily,
keywordstyle=\crBlue\bfseries,
commentstyle=\crRed,
numbers=none,
numberstyle=\tiny\ttfamily,
mathescape=false,
escapeinside={\%*}{*)},
stepnumber=1,
showspaces=false,
showstringspaces=false,
showtabs=false,
breaklines=true,
frame=tb,
framerule=0.5pt,
tabsize=4,
framexleftmargin=0.5em,
framexrightmargin=0.5em,
xleftmargin=0.5em,
xrightmargin=0.5em
}}
{}

\lstset{
basicstyle=\small\ttfamily,
}

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	GLOBAL MATH
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

\newcommand{\limit}{\displaystyle\lim}
\newcommand{\impart}{\textrm{Im}}
\newcommand{\repart}{\textrm{Re}}
\newcommand{\integer}{\mathbb{Z}}
\newcommand{\degree}{\ensuremath{{}^{\circ}}\xspace}
%\newcommand{\degree}{^{\circ}} Depricated by above
\newcommand{\rad}{\unit{rad}}
\newcommand{\dd}{\mathrm{d}}
\newcommand{\dx}{\mathrm{d}x}
\newcommand{\dy}{\mathrm{d}y}
\newcommand{\dr}{\mathrm{d}r}
\newcommand{\dtheta}{\mathrm{d}\theta}
\newcommand{\dydx}{\dfrac{\mathrm{d}y}{\mathrm{d}x}}
\newcommand{\dydt}{\dfrac{\mathrm{d}y}{\mathrm{d}t}}
\newcommand{\dxdt}{\dfrac{\mathrm{d}x}{\mathrm{d}t}}
\newcommand{\vect}[1]{\boldsymbol{#1}}
\newcommand{\farg}[1]{{\color{sthlmBlue}{\left[\boldsymbol{#1}\right]}}}
\newcommand{\sname}[1]{\texttt{#1}}
\newcommand{\set}[1]{\left\{#1\right\}}
\newcommand{\inv}{^{-1}}
\newcommand{\cb}{$\Box$}
\newcommand{\suchthat}{\;\ifnum\currentgrouptype=16 \middle\fi|\;}
\newcommand{\ihat}{\hat{\imath}}
\newcommand{\jhat}{\hat{\jmath}}
\newcommand{\khat}{\hat{k}}

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	LISTINGS PACKAGE
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

\usepackage{listings}
\lstset{ %
language=[LaTeX]TeX,
basicstyle=\normalsize\ttfamily,
keywordstyle=,
numbers=left,
numberstyle=\tiny\ttfamily,
stepnumber=1,
showspaces=false,
showstringspaces=false,
showtabs=false,
breaklines=true,
frame=tb,
framerule=0.5pt,
tabsize=4,
framexleftmargin=0.5em,
framexrightmargin=0.5em,
xleftmargin=0.5em,
xrightmargin=0.5em
}

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	03. COLOR AND FONT THEMES (BEAMER)
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

\usecolortheme{sthlm}
\usefonttheme{sthlm}

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	04. TITLE PAGE
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\def\maketitle{\ifbeamer@inframe\titlepage\else\frame[plain]{\titlepage}\fi}

\def\titlepage{\usebeamertemplate{title page}}
\setbeamertemplate{title page}
{
  \begin{minipage}[b][\paperheight]{\textwidth}
    \vfill
    \vspace*{2em}
    \ifx\inserttitle\@empty%
    \else%
    {\raggedright\linespread{1.0}\usebeamerfont{title}\usebeamercolor[fg]{title}\inserttitle\par}%
    \vspace*{0.5em}
    \fi%
    \begin{tikzpicture}\draw[normal text.fg] (0, 0) -- (\textwidth, 0);\end{tikzpicture}%
    \vspace*{0.5em}
    \ifx\insertsubtitle\@empty%
    \else%
    {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}%
    \vspace*{5em}
    \fi%
    
    \ifx\insertauthor\@empty%
    \else%
    {\usebeamerfont{author}\usebeamercolor[fg]{author}\insertauthor \par}%
    \vspace*{0mm}
    \fi%
    \ifx\insertinstitut\@empty%
    \else%
    \vspace*{0mm}
    {\usebeamerfont{institute}\usebeamercolor[fg]{institute}\insertinstitute\par}%
    \fi%
    \ifx\insertdate\@empty%
    \else%
    {\usebeamerfont{date}\usebeamercolor[fg]{date}\insertdate \par}%
    \fi%
    
    \vfill
 	\hfill \includegraphics[height=10mm]{logo_suibe} \hspace{0mm} \par
    \vspace*{4mm}
  \end{minipage}
}

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	05. TABLE OF CONTENTS
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\setbeamertemplate{section in toc}[sections numbered]
%\setbeamertemplate{sections in toc}[ball]
\setbeamertemplate{subsection in toc}[subsections numbered]


%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	06. PROGRESS BAR & HEADLINE
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\makeatletter
\def\progressbar@sectionprogressbar{}
\def\progressbar@titleprogressbar{}
\newcount\progressbar@tmpcounta % auxiliary counter
\newcount\progressbar@tmpcountb % auxiliary counter
\newdimen\progressbar@pbht      % progressbar height
\newdimen\progressbar@pbwd      % progressbar width
\newdimen\progressbar@tmpdim    % auxiliary dimension

\progressbar@pbwd=20em
\progressbar@pbht=2pt

% the progress bar
\def\progressbar@sectionprogressbar{%
  {\usebeamercolor{palette quaternary}%
    \progressbar@tmpcounta=\insertframenumber
    \progressbar@tmpcountb=\inserttotalframenumber
    \progressbar@tmpdim=\progressbar@pbwd
    \divide\progressbar@tmpdim by 1000
    \multiply\progressbar@tmpdim by \progressbar@tmpcounta
    \divide\progressbar@tmpdim by \progressbar@tmpcountb
    \multiply\progressbar@tmpdim by 1000
    \fontsize{1em}{1em}\selectfont

    \makebox[\textwidth][c]{
      \begin{tikzpicture}[tight background]

        \node[anchor=south west, fg, inner sep=0pt, text width=\progressbar@pbwd] at (0pt, 0pt) {\insertsectionHEAD};

        \draw[anchor=west, fg, fill=fg, inner sep=0pt]
        (0, -1ex) rectangle ++ (\progressbar@pbwd, \progressbar@pbht);

        \draw[anchor=west, bg, fill=bg, inner sep=0pt]
        (0, -1ex) rectangle ++ (\progressbar@tmpdim, \progressbar@pbht);
      \end{tikzpicture}%
    }
  }
}

\if@useTitleProgressBar
\def\progressbar@titleprogressbar{%
  \progressbar@tmpcounta=\insertframenumber
  \progressbar@tmpcountb=\inserttotalframenumber
  \progressbar@tmpdim=\paperwidth
  \divide\progressbar@tmpdim by 1000
  \multiply\progressbar@tmpdim by \progressbar@tmpcounta
  \divide\progressbar@tmpdim by \progressbar@tmpcountb
  \multiply\progressbar@tmpdim by 1000
  {%
    \usebeamercolor{palette quaternary}%
    \begin{tikzpicture}[tight background]
      \draw[fg, fill=fg] (0, 0) rectangle ($(\paperwidth, 2pt) - (0.4pt, 0)$);
      \draw[bg, fill=bg] (0, 0) rectangle (\progressbar@tmpdim, 2pt);
    \end{tikzpicture}%
  }%
}
\fi

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	07. SECTION PAGES
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\if@doSectionPage
\newcommand{\insertsectionHEAD}{%
  \expandafter\insertsectionHEADaux\insertsectionhead}
  \newcommand{\insertsectionHEADaux}[3]{\textsc{#3}
}

\AtBeginSection[]
{
  \begingroup
  \setbeamercolor{background canvas}{parent=palette primary}
  \begin{frame}[plain]
    \vspace{2em}\usebeamerfont{section title}
    \progressbar@sectionprogressbar%
  \end{frame}
  \endgroup
}
\else
\fi

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	08. ITEMIZE
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\setbeamertemplate{itemize item}{$\Circle$}
\setbeamertemplate{itemize subitem}{$\circ$}
\setbeamertemplate{itemize subsubitem}{$\circ$}
\setlength{\parskip}{0.5em}

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	09. FOOTLINE
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\usenavigationsymbolstemplate{}

\if@dosthlmFooter
\setbeamertemplate{footline}{
\hbox{
\begin{beamercolorbox}[wd=0.25\textwidth,dp=1.5ex,leftskip=0.3cm,rightskip=0.3cm]{structure}
%\includegraphics[width=0.08\textwidth]{xidian-logo1}
\end{beamercolorbox}
\begin{beamercolorbox}[wd=0.75\textwidth, dp=1.5ex,leftskip=0.3cm,rightskip=0.3cm plus1fil]{structure}
%\hfill \includegraphics[width=0.1\textwidth]{xidian-logo1}
\usebeamerfont{page number in head/foot}
%\hfill\insertdate 
\newline

\vspace*{0em}

\hfill  \insertframenumber
\vspace*{1em}
\end{beamercolorbox}
}}
\else%
\usenavigationsymbolstemplate{}
\fi%

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	10. CAPTIONS
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%\setbeamertemplate{caption label separator}{: }
\setbeamertemplate{caption}[numbered]
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	11. FRAME TITLE
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\setbeamertemplate{frametitle}{%
\nointerlineskip
\begin{beamercolorbox}[wd=\paperwidth,leftskip=0.3cm,rightskip=0.3cm,ht=2.5ex,dp=1.5ex]{frametitle}
\if@protectFrameTitle
  \usebeamerfont{frametitle}{\protect\insertframetitle}%
\else
  \usebeamerfont{frametitle}{\insertframetitle}%
\fi
\end{beamercolorbox}%
\if@useTitleProgressBar
  \vspace{-.5em}
\if@donewPxFont
 \vspace{-.1em}
\else
\vspace{-.15em}
\fi
  \begin{beamercolorbox}[wd=\paperwidth,ht=1pt,dp=0pt]{frametitle}
    \progressbar@titleprogressbar
  \end{beamercolorbox}
\fi
\vspace{\@sthlm@voffset}
}

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	12. IMAGES
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\newbox\mytempbox
\newdimen\mytempdimen

\newcommand\includegraphicscopyright[3][]{%
  \leavevmode\vbox{\vskip3pt\raggedright\setbox\mytempbox=\hbox{\includegraphics[#1]{#2}}%
    \mytempdimen=\wd\mytempbox\box\mytempbox\par\vskip1pt%
    \usebeamerfont{copyright text}{\usebeamercolor[fg]{copyright text}{\vbox{\hsize=\mytempdimen#3}}}\vskip3pt%
}}

%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%	13. BLOCKS
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\setbeamertemplate{block begin}
{
\setbeamercolor{item}{parent=block body}
\par\vskip\medskipamount%
\begin{beamercolorbox}[sep=.5ex,dp=0.6ex,leftskip=0.5ex,rightskip=0.5ex]{block title}
\usebeamerfont*{block title}\insertblocktitle%
\end{beamercolorbox}%
{\parskip0pt\par}%
{\nointerlineskip\vskip-0.5pt}%
\usebeamerfont{block body}%
\begin{beamercolorbox}[sep=.5ex,dp=0.6ex,leftskip=0.5ex,rightskip=0.5ex,vmode]{block body}%
}
\setbeamertemplate{block end}
{\end{beamercolorbox}\vskip\smallskipamount}

\setbeamertemplate{block alerted begin}
{
\setbeamercolor{item}{parent=block body alerted}
\par\vskip\medskipamount%
\begin{beamercolorbox}[sep=.5ex,dp=0.6ex,leftskip=0.5ex,rightskip=0.5ex]{block title alerted}
\usebeamerfont*{block title alerted}\insertblocktitle%
\end{beamercolorbox}%
{\parskip0pt\par}%
{\nointerlineskip\vskip-0.5pt}%
\usebeamerfont{block body alerted}%
\begin{beamercolorbox}[sep=.5ex,dp=0.6ex,leftskip=0.5ex,rightskip=0.5ex,vmode]{block body alerted}%
}
\setbeamertemplate{block alerted end}
{\end{beamercolorbox}\vskip\smallskipamount}

\setbeamertemplate{block example begin}
{
\par\vskip\medskipamount%
\begin{beamercolorbox}[sep=.5ex,dp=0.6ex,leftskip=0.5ex,rightskip=0.5ex]{block title example}
\usebeamerfont*{block title example}\insertblocktitle%
\end{beamercolorbox}%
{\parskip0pt\par}%
{\nointerlineskip\vskip-0.5pt}%
\usebeamerfont{block body example}%
\begin{beamercolorbox}[sep=.5ex,dp=0.6ex,leftskip=0.5ex,rightskip=0.5ex,vmode]{block body example}%
}
\setbeamertemplate{block example end}
{\end{beamercolorbox}\vskip\smallskipamount}

\mode
<all>

\let\otp\titlepage
\renewcommand{\titlepage}{\otp\addtocounter{framenumber}{-1}}
\newcommand{\mreducelistspacing}{\vspace{-\topsep}}

\linespread{1.15}